import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { EPetWarhouseExpand } from "../../../../Message/Game/EPetWarhouseExpand";
import { ObjCreate } from "../common/ObjCreate";
import { ItemConfig } from "../../resource/ItemConfig";
import { RadioButtonGroup } from "../../../../fl/controls/RadioButtonGroup";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ImagesConst } from "../../resource/ImagesConst";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { _EPetWarhouseExpandSimple } from "../../../../EPetWarhouseExpand/_EPetWarhouseExpandSimple";
import { _EPetWarhouseExpandAll } from "../../../../EPetWarhouseExpand/_EPetWarhouseExpandAll";
type int = number;
//class PetWareHouseExpendWindow
    
    export  class PetWareHouseExpendWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            this._dataArr = [{"name": Language.getStringByParam(35111, 1), "expandType": _EPetWarhouseExpandSimple}, {"name": Language.getStringByParam(35112, 4), "expandType": _EPetWarhouseExpandAll}];
            this._btnDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._costArr = [];
            super(arg1);
            setSize(240, 210);
            title = Language.getString(35113);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc2=null;
            super.createChildren();
            ObjCreate.createBg(18, 42, 204, 158, this);
            this._costArr = ItemConfig.instance.getPetWarehouseExpansionCost();
            var loc1=new RadioButtonGroup("rbg");
            var loc3=40;
            var loc4=50;
            var loc5=0;
            while (loc5 < this._dataArr.length) 
            {
                loc2 = ObjCreate.createRadioButton(this._dataArr[loc5].name, loc3, loc4, 180, 30, this, "GRadioButton");
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onRadioBtnClickHandler);
                loc2.value = this._dataArr[loc5].expandType;
                loc2.group = loc1;
                loc4 = loc4 + 47;
                this._btnDic[loc2.value] = loc2;
                ++loc5;
            }
            this._costTxt = ObjCreate.createTextField("", 55, 80, 150, 20, this, GlobalStyle.textFormat2);
            this._allCostTxt = ObjCreate.createTextField("", 55, 127, 150, 20, this, GlobalStyle.textFormat2);
            var loc6=ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 130, 80, this);
            var loc7=ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 130, 128, this);
            var loc8;
            (loc8 = ObjCreate.createGButton(Language.getString(35114), 80, 160, 80, 25, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            return;
        }

        /* internal  */onRadioBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GRadioButton;
            this._expandType = loc1.value as int;
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._expandType == -1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(35116));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetWareHouse_ExpendCapacitySure, this._expandType));
            }
            this.hide();
            return;
        }

        public updateCost(): void
        {
            var loc6=0;
            var loc1=this._btnDic[EPetWarhouseExpand._EPetWarhouseExpandSimple] as GRadioButton;
            var loc2=this._btnDic[EPetWarhouseExpand._EPetWarhouseExpandAll] as GRadioButton;
            var loc3=Cache.instance.petWareHouse.capacity;
            var loc4=24 - loc3;
            var loc5;
            var loc7=loc5 = 20 - loc4;
            while (loc7 < 20) 
            {
                loc6 = loc6 + this._costArr[loc7][1];
                ++loc7;
            }
            this._costTxt.text = Language.getString(35115) + this._costArr[loc3 - 4][1];
            this._allCostTxt.text = Language.getString(35115) + loc6;
            loc1.label = Language.getStringByParam(35111, loc3 - 3);
            loc2.label = Language.getStringByParam(35112, loc4);
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.updateCost();
            return;
        }

        /* internal */ /* var */_expandType: int=-1;

        /* internal */ /* var */_dataArr: Array<any>;

        /* internal */ /* var */_btnDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_allCostTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costArr: Array<any>;
    }
